﻿using DBServer.Selenium.Extenium.Exception;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class CellFixture : GridFixture
    {
        private readonly int _row;
        private readonly int _column;

        public CellFixture(ISelenium driver, string name, int row, int column)
            : base(driver, name)
        {
            _row = row;
            _column = column;
        }

        public string GetValue()
        {
            var command =
                " window.Ext.fly( " +
                    Path.Eval() + ".getView().getCell(" + _row + ", " + _column + ")" +
                " ).child('div.x-grid3-cell-inner').dom.innerHTML ";
            var eval = SafeExec(command);
            if (eval != "null")
            {
                return eval;
            }
            throw new ExteniumException("Cell not found: row:" + _row + " column:" + _column);

        }

        public CellFixture RequireText(string text)
        {
            Assert.AreEqual(text, GetValue());
            return this;
        }
    }
}